package net.ib.mtalk.ui.widget;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.view.KeyEvent;

public class MtalkProgressBar {
	private Context parent;
	
	public MtalkProgressBar (Context mContext) {
		this.parent = mContext;
	}
	
	public Dialog onCreate (String str) {
		ProgressDialog mProgressDialog = (ProgressDialog) setDialogAttribute();
		mProgressDialog.setMessage(str);
		return mProgressDialog;
	}
	
	public Dialog onCreate(int titleResId) {
		ProgressDialog mProgressDialog = (ProgressDialog) setDialogAttribute();
		mProgressDialog.setMessage(parent.getString(titleResId));
		return mProgressDialog;
	}
	
	private Dialog setDialogAttribute() {
		ProgressDialog mProgressDialog = new ProgressDialog(parent);
		mProgressDialog.setCancelable(false);
		mProgressDialog.setOnKeyListener(new OnKeyListener() {
			@Override
			public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
				if (keyCode == KeyEvent.KEYCODE_SEARCH) {
					return true;
				} else {
					return false;
				}
			}
		});		
		return mProgressDialog;
	}

}